import { View } from "../../../../mvc/core/View";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { TilePanel } from "../../equipment/TilePanel";
import { GuildWarGuildCellRenderer } from "./GuildWarGuildCellRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { GTextArea } from "../../../../../com/mui/controls/GTextArea";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TToplist } from "../../../../../Message/Db/Tables/TToplist";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class GuildWarPanel
    
    export  class GuildWarPanel extends View
    {
        constructor()
        {
            super();
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ObjCreate.createSpBannerAndBg(0, 0, 444, 96, Language.getString(57191), this);
            var loc2=ObjCreate.createSpBannerAndBg(0, 100, 444, 267, "", this);
            ObjCreate.createBg(449, 0, 213, 366, this);
            var loc3=Language.getString(57195);
            this._tfMyMerits = this.createText(Language.getString(57192), loc3, 82, 40, 120, 20);
            this._tfMyKillNum = this.createText(Language.getString(57193), loc3, 268, 40, 120, 20);
            this._tfMyRank = this.createText(Language.getString(57194), loc3, 82, 65, 120, 20);
            this._tfMyAssistsNum = this.createText(Language.getString(41837), loc3, 268, 65, 120, 20);
            var loc4=new GBox();
            var loc5;
            (loc5 = new GTextFormat(FontUtil.songtiName, 12, 15788607)).align = flash.text.TextFormatAlign.CENTER;
            ObjCreate.createTextField(Language.getString(57196), 0, 0, 70, 20, loc4, loc5);
            ObjCreate.createTextField(Language.getString(57197), 0, 0, 110, 20, loc4, loc5);
            ObjCreate.createTextField(Language.getString(57199), 0, 0, 70, 20, loc4, loc5);
            ObjCreate.createTextField(Language.getString(57200), 0, 0, 85, 20, loc4, loc5);
            ObjCreate.createTextField(Language.getString(41838), 0, 0, 85, 20, loc4, loc5);
            loc4.x = 10;
            loc4.y = 8;
            loc2.addChild(loc4);
            this._guildTopListPanel = new TilePanel();
            this._guildTopListPanel.setSize(430, 214);
            this._guildTopListPanel.rowHeight = 35;
            this._guildTopListPanel.columnWidth = 430;
            this._guildTopListPanel.setStyle("cellRenderer", GuildWarGuildCellRenderer);
            this._guildTopListPanel.x = 10;
            this._guildTopListPanel.y = 34;
            loc2.addChild(this._guildTopListPanel);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.x = 156;
            this._pageSelecter.y = 240;
            loc2.addChild(this._pageSelecter);
            this._btnJoin = ObjCreate.createGButton(Language.getString(57201), 300, 372, 70, 26, this, "ButtonLarge");
            this.initRightPart();
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this._btnJoin.addEventListener(flash.events.MouseEvent.CLICK, this.onJoin);
            return;
        }

        /* internal  */initRightPart(): void
        {
            this._tfRightDes = new GTextArea();
            ObjCreate.setObjAttri(this._tfRightDes, 460, 10, 195, 340, this);
            this._tfRightDes.styleName = "GTextArea";
            this._tfRightDes.wordWrap = true;
            this._tfRightDes.editable = false;
            this._tfRightDes.htmlText = Language.getString(57202);
            return;
        }

        /* internal  */createText(arg1: string, arg2: string, arg3: number=0, arg4: number=0, arg5: number=100, arg6: number=20): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = ObjCreate.createTextField("", arg3, arg4, arg5, arg6)).mouseEnabled = false;
            loc1.htmlText = HTMLUtil.addColor(arg1, GlobalStyle.color2) + HTMLUtil.addColor(arg2, GlobalStyle.color1);
            this.addChild(loc1);
            return loc1;
        }

        /* internal  */updateText(arg1: Object /* flash.text.TextField */, arg2: string, arg3: string): void
        {
            arg1.htmlText = HTMLUtil.addColor(arg2, GlobalStyle.color2) + HTMLUtil.addColor(arg3, GlobalStyle.color1);
            return;
        }

        /* internal  */addListeners(): void
        {
            return;
        }

        public updateMyScore(arg1: TToplist): void
        {
            if (!arg1) 
            {
                return;
            }
            this.updateText(this._tfMyRank, Language.getString(57194), arg1.rank.toString());
            this.updateText(this._tfMyKillNum, Language.getString(57193), arg1.valueTwo.toString());
            this.updateText(this._tfMyMerits, Language.getString(57192), arg1.valueOne.toString());
            this.updateText(this._tfMyAssistsNum, Language.getString(41837), arg1.valueThree.toString());
            return;
        }

        public updateGuildScore(arg1: Array<any>, arg2: TToplist): void
        {
            if (!arg1 || arg1.length == 0) 
            {
                return;
            }
            this._guildScoreList = arg1;
            this._myGuildTopList = arg2;
            this._pageSelecter.maxPage = Math.ceil(this._guildScoreList.length / this.pageSize);
            this._pageSelecter.currentPage = 1;
            this.updateList();
            return;
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this.updateList();
            return;
        }

        /* internal  */onJoin(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (GameMapUtil.isGuildWar()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57203));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarEnter));
            }
            return;
        }

        /* internal  */updateList(): void
        {
            this._guildTopListPanel.dataProvider = this.getDataProvider();
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            var loc1=new Array<any>();
            var loc2=(this._pageSelecter.currentPage - 1) * this.pageSize;
            var loc3=Math.min(this._pageSelecter.currentPage * this.pageSize, this._guildScoreList.length);
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(this._guildScoreList[loc4]);
                ++loc4;
            }
            return new DataProvider(loc1);
        }

        /* internal */ /* var */_tfMyMerits: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMyKillNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMyRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMyAssistsNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_guildTopListPanel: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_btnJoin: GButton;

        /* internal */ /* var */_tfRightDes: GTextArea;

        /* internal */ /* var */_guildScoreList: Array<any>;

        /* internal */ /* var */_myGuildTopList: TToplist;

        /* internal */ /* var */pageSize: int=6;
    }
